package sopt.dev.data;

import java.util.ArrayList;
import android.os.Parcel;
import android.os.Parcelable;

public class CityVO<T> extends Info implements Parcelable{

	private int currency;
	private String inDate;
	private String outDate;
	private ArrayList<T> itemList = new ArrayList<T>();

	public CityVO(String picPath, String cityName, int cityMoney, String inString, String outString) {
		this.picPath = picPath;
		this.name = cityName;
		this.currency = cityMoney;
		this.inDate = inString;
		this.outDate = outString;

	}

	public CityVO(String picPath, String cityName, int cityMoney, String inString, String outString, ArrayList<T> item) {
		this.picPath = picPath;
		this.name = cityName;
		this.currency = cityMoney;
		this.inDate = inString;
		this.outDate = outString;
		this.itemList = item;
	}


	public CityVO(Parcel src) {
		picPath = src.readString();
		name = src.readString();
		currency = src.readInt();
		inDate = src.readString();
		outDate = src.readString();
	}

	public String getPicPath() {
		return picPath;
	}

	public String getCityName() {
		return name;
	}

	public int getCityMoney() {
		return currency;
	}

	public String getInString() {
		return inDate;
	}

	public String getOutString() {
		return outDate;
	}

	public T getItemByIndex(int index) {
		return itemList.get(index);
	}

	public void addItem(T obj) {
		itemList.add(obj);
	}

	public void removeItem(int index) {
		itemList.remove(index);
	}

	public void removeItem(ItemVO item) {
		itemList.remove(item);
	}

	public void updateItem(T updatedItem) {
		for(T item : itemList) {
			if(item.equals(updatedItem))
				item = updatedItem;
		}
	}

	public ArrayList<T> getItemList() {
		return itemList;
	}


	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel parcel, int i) {
		parcel.writeString(picPath);
		parcel.writeString(name);
		parcel.writeInt(currency);
		parcel.writeString(inDate.toString());
		parcel.writeString(outDate.toString());
	}

	public static Parcelable.Creator<CityVO<ItemVO>> CREATOR = new Creator<CityVO<ItemVO>>() {

		@Override
		public CityVO<ItemVO>[] newArray(int size) {
			return new CityVO[size];
		}

		@Override
		public CityVO<ItemVO> createFromParcel(Parcel src) {
			return new CityVO<ItemVO>(src);
		}
	};
}
